package cn.com.lms.business.user.persistence.repository;

import cn.com.lms.business.user.persistence.entity.SysUserVo;
import com.bnzj.core.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @Author: 16266
 * @DateTime: 2020/3/27 17:28
 * @Description:
 */
@Repository
public interface SysUserVoRepository extends BaseRepository<SysUserVo, Long> {

    /**
     * 根据用户名查询用虎
     *
     * @param empNo
     * @return
     */
    @Query(value = "select * from bnz_sys_user where personnel = 1 and enabled = 1 and account=?1", nativeQuery = true)
    SysUserVo findByAccount(String empNo);

    /**
     * 根据用户名查询用虎
     *
     * @param phone
     * @return
     */
    @Query(value = "select * from bnz_sys_user where personnel = 1 and enabled = 1 and phone=?1", nativeQuery = true)
    SysUserVo findByPhoneNo(String phone);

    /**
     * 查询用户表岗位分类
     *
     * @return
     */
    @Query(value = "select DISTINCT(job_type_name) from bnz_sys_user where job_type_name is not null", nativeQuery = true)
    List<String> findJobTypeName();

    /**
     * 查询部门人员信息
     */
    @Query(value = "select id,account,cname,email,sex,phone,identity,ename,dept_id as deptId,personnel,enabled,job_type_name jobTypeName from  bnz_sys_user  WHERE personnel=true  and   job_type_name in (:collection)", nativeQuery = true)
    List<Map> findSysUserVoByJobTypeNames(@Param("collection") Collection<String> collection) ;


    /**
     * 根据岗位查询岗位人员信息
     */
    @Query(value = "select id,account,cname,email,sex,phone,identity,ename,dept_id as deptId,personnel,enabled,job_type_name jobTypeName from  bnz_sys_user  WHERE  personnel=true and  dept_id in (:collection)", nativeQuery = true)
    List<Map> findSysUserVoByDepartmentIds(@Param("collection") Collection<Long> collection) ;


}
